<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>json</title>
</head>
<body>
<script>
    let p1 = {
        name: 'jerry',
        age: 22,
        hobby: ['game', 'movie']
    }
    let p2 = {
        name: '刘备',
        age: 30,
        partner: [
            {name: '关羽', age: 22},
            {name: '张飞', age: 23}
        ]
    }
    //将json对象转换为字符串
    let jsonStr = JSON.stringify(p2)
    console.log(jsonStr);
    console.log(typeof jsonStr);

    //将json字符串转换为json对象
    let jsonObj = JSON.parse(jsonStr)
    console.log(jsonObj);
    console.log(typeof jsonObj);
    console.log(jsonObj.partner[0].name);
    console.log(jsonObj.partner[1].name);

</script>
</body>
</html>